use std::rc::Rc;
use std::sync::atomic;
use std::sync::{Arc, Mutex};
use std::thread;
fn main() {
    let m = Mutex::new(5);
    {
        let mut num = m.lock().unwrap();
        *num = 6;
    }
    println!("m = {:?}", m);
    count();
}
fn count() {
    let counter = Arc::new(Mutex::new(0));

    let mut handles = vec![];

    // Rc和引用 我认为主要区别是生命周期的管理
    //可变性 指是否能和vec和数组的区别
    for _ in 0..10 {
        let counter = Arc::clone(&counter);
        let handle: thread::JoinHandle<()> = thread::spawn(move || {
            let mut num = counter.lock().unwrap();
            *num += 1;
        });
        handles.push(handle);
    }
    for handle in handles {
        handle.join().unwrap();
    }
    println!("Result: {}", *counter.lock().unwrap())
}
